package com.zhw.andfix.model;

import java.util.List;

import cn.droidlover.xdroidmvp.net.IModel;

/**
 * Created by Administrator on 2016/12/11.
 */

public class BaseModel implements IModel {
    /**
     * result : null
     * _zap : true
     * success : false
     * unAuthorizedRequest : false
     * targetUrl : null
     * error : {"code":0,"message":"ValidationError","details":"ValidationNarrativeTitle\r\n - \r\n - loginModel is null!\r\n","validationErrors":[{"message":"","members":[""]},{"message":"loginModel is null!","members":["loginModel"]}]}
     */

    private boolean _zap;
    private boolean success;
    private boolean unAuthorizedRequest;
    private int code;
    private String message;
    private String targetUrl;
    private ErrorBean error;



    @Override
    public boolean isNull() {
        return false;
    }

    @Override
    public boolean isAuthError() {
        return false;
    }

    @Override
    public boolean isBizError() {
        return false;
    }

    @Override
    public String getErrorMsg() {
        return null;
    }

    public boolean is_zap() {
        return _zap;
    }

    public void set_zap(boolean _zap) {
        this._zap = _zap;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public boolean isUnAuthorizedRequest() {
        return unAuthorizedRequest;
    }

    public void setUnAuthorizedRequest(boolean unAuthorizedRequest) {
        this.unAuthorizedRequest = unAuthorizedRequest;
    }

    public String getTargetUrl() {
        return targetUrl;
    }

    public void setTargetUrl(String targetUrl) {
        this.targetUrl = targetUrl;
    }

    public int getCode() {
        if (error != null){
            code = error.getCode();
        }
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        if (error != null){
            message = error.getMessage();
        }
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public ErrorBean getError() {
        return error;
    }

    public void setError(ErrorBean error) {
        this.error = error;
        if (error != null){
            setMessage(error.getMessage());
            setCode(error.getCode());
        }
    }

    public static class ErrorBean {
        /**
         * code : 0
         * message : ValidationError
         * details : ValidationNarrativeTitle
         -
         - loginModel is null!

         * validationErrors : [{"message":"","members":[""]},{"message":"loginModel is null!","members":["loginModel"]}]
         */

        private int code;
        private String message;
        private String details;
        private List<ValidationErrorsBean> validationErrors;

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public String getDetails() {
            return details;
        }

        public void setDetails(String details) {
            this.details = details;
        }

        public List<ValidationErrorsBean> getValidationErrors() {
            return validationErrors;
        }

        public void setValidationErrors(List<ValidationErrorsBean> validationErrors) {
            this.validationErrors = validationErrors;
        }

        public static class ValidationErrorsBean {
            /**
             * message :
             * members : [""]
             */

            private String message;
            private List<String> members;

            public String getMessage() {
                return message;
            }

            public void setMessage(String message) {
                this.message = message;
            }

            public List<String> getMembers() {
                return members;
            }

            public void setMembers(List<String> members) {
                this.members = members;
            }

            @Override
            public String toString() {
                return "ValidationErrorsBean{" +
                        "message='" + message + '\'' +
                        ", members=" + members +
                        '}';
            }
        }

        @Override
        public String toString() {
            return "ErrorBean{" +
                    "code=" + code +
                    ", message='" + message + '\'' +
                    ", details='" + details + '\'' +
                    ", validationErrors=" + (validationErrors == null ? "" : validationErrors) +
                    '}';
        }
    }

    @Override
    public String toString() {
        return "BaseModel{" +
                ", _zap=" + _zap +
                ", success=" + success +
                ", unAuthorizedRequest=" + unAuthorizedRequest +
                ", targetUrl=" + targetUrl +
                ", error=" + (error == null ? "" : error.toString()) +
                '}';
    }
}
